package we.core.bean;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;


public class CRoom {
    static AtomicInteger idSequence = new AtomicInteger(0);

    int id;
    String name;

    Map<String, CUser> playerList;
    Map<String, CUser> viewerList;

    int maxUser;
    String password;
    String roomOwner;
    HashMap<String, String> properties;

    public CRoom(String roomOwner, String roomName, int maxUser,
                String password) {
        this.roomOwner = roomOwner;
        this.id = idSequence.getAndIncrement();
        this.name = roomName;

        this.maxUser = maxUser;
        this.password = password;

        this.playerList = new HashMap<String, CUser>();
        this.viewerList = new HashMap<String, CUser>();
    }

    public int getRoomId() {
        return id;
    }

    public void removeUser(String username) {
        playerList.remove(username);
        //viewerList.remove(username);
    }

    public void addUser(CUser u) {
        playerList.put(u.username, u);

    }

    public String getPassword() {
        return password;
    }

    public List<CUser> getPlayerList() {
        List<CUser> list = new ArrayList();
        Iterator<Map.Entry<String, CUser>> it = playerList.entrySet().iterator();
        while(it.hasNext()){
              list.add( it.next().getValue() ); 
        }
        return list;
    }
}
